package repository

import (
	"lzppp/internal/app/model"

	"lzppp/internal/bootstrap"
)

func GetAllUsers() ([]model.User, error) {
	var users []model.User
	result := bootstrap.DB.Find(&users)
	return users, result.Error
}

// GetUsers 查询用户，可选 name
func GetUsers(name string) ([]model.User, error) {
	var users []model.User
	db := bootstrap.DB

	if name != "" {
		db = db.Where("name LIKE ?", "%"+name+"%") // 模糊查询
	}

	result := db.Find(&users)
	return users, result.Error
}

func InsertUser(user *model.User) error {
	res := bootstrap.DB.Create(&user)
	return res.Error
}
